begintownscript;

variables;

	short x, y, what_num, which_state, progress;
	string prompt;

body;

beginstate INIT_STATE;
	
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
	x = 0;
	while(x < 22){
		if(char_ok(x) == 0)
			spawn_creature(x);
		x = x + 1;
	}
	y = 13;
	while(y < 18){
		x = 19;
		while(x < 29){
			put_field_on_space(x,y,-1);
			x = x + 1;
		}
		y = y + 1;
	}
	change_char_energy(0,1000);
break;

beginstate 11;
	// Numeric input function. Sets variable what_num to whatever the input was.
	// Then goes to which_state, which was presumably defined in the state that
	// called this function.
	//
	// NOTE: This function uses the variable just_selected to tell whether BoA
	// is returning from the function or hasn't started it yet. Make sure
	// just_selected is 0 when you begin the state that calls this function, and
	// make sure to zero it again after this function is over.
	
	what_num = 0;
	
	get_text_response(prompt);
	check_text_response_match("1");
	if (got_text_match())
		what_num = 1;
	check_text_response_match("2");
	if (got_text_match())
		what_num = 2;
	check_text_response_match("3");
	if (got_text_match())
		what_num = 3;
	check_text_response_match("4");
	if (got_text_match())
		what_num = 4;
	check_text_response_match("5");
	if (got_text_match())
		what_num = 5;
	check_text_response_match("6");
	if (got_text_match())
		what_num = 6;
	check_text_response_match("7");
	if (got_text_match())
		what_num = 7;
	check_text_response_match("8");
	if (got_text_match())
		what_num = 8;
	check_text_response_match("9");
	if (got_text_match())
		what_num = 9;
	check_text_response_match("10");
	if (got_text_match())
		what_num = 10;
	check_text_response_match("11");
	if (got_text_match())
		what_num = 11;
	check_text_response_match("12");
	if (got_text_match())
		what_num = 12;
	check_text_response_match("13");
	if (got_text_match())
		what_num = 13;
	check_text_response_match("14");
	if (got_text_match())
		what_num = 14;
	check_text_response_match("15");
	if (got_text_match())
		what_num = 15;
	check_text_response_match("16");
	if (got_text_match())
		what_num = 16;
	check_text_response_match("17");
	if (got_text_match())
		what_num = 17;
	check_text_response_match("18");
	if (got_text_match())
		what_num = 18;
	check_text_response_match("19");
	if (got_text_match())
		what_num = 19;
	check_text_response_match("20");
	if (got_text_match())
		what_num = 20;
	check_text_response_match("21");
	if (got_text_match())
		what_num = 21;
	check_text_response_match("22");
	if (got_text_match())
		what_num = 22;
	check_text_response_match("23");
	if (got_text_match())
		what_num = 23;
	check_text_response_match("24");
	if (got_text_match())
		what_num = 24;
	check_text_response_match("25");
	if (got_text_match())
		what_num = 25;
	check_text_response_match("26");
	if (got_text_match())
		what_num = 26;
	check_text_response_match("27");
	if (got_text_match())
		what_num = 27;
	check_text_response_match("28");
	if (got_text_match())
		what_num = 28;
	check_text_response_match("29");
	if (got_text_match())
		what_num = 29;
	check_text_response_match("30");
	if (got_text_match())
		what_num = 30;
	check_text_response_match("31");
	if (got_text_match())
		what_num = 31;
	check_text_response_match("32");
	if (got_text_match())
		what_num = 32;
	check_text_response_match("33");
	if (got_text_match())
		what_num = 33;
	check_text_response_match("34");
	if (got_text_match())
		what_num = 34;
	check_text_response_match("35");
	if (got_text_match())
		what_num = 35;
	check_text_response_match("36");
	if (got_text_match())
		what_num = 36;
	check_text_response_match("37");
	if (got_text_match())
		what_num = 37;
	check_text_response_match("38");
	if (got_text_match())
		what_num = 38;
	check_text_response_match("39");
	if (got_text_match())
		what_num = 39;
	check_text_response_match("40");
	if (got_text_match())
		what_num = 40;
	check_text_response_match("41");
	if (got_text_match())
		what_num = 41;
	check_text_response_match("42");
	if (got_text_match())
		what_num = 42;
	check_text_response_match("43");
	if (got_text_match())
		what_num = 43;
	check_text_response_match("44");
	if (got_text_match())
		what_num = 44;
	check_text_response_match("45");
	if (got_text_match())
		what_num = 45;
	check_text_response_match("46");
	if (got_text_match())
		what_num = 46;
	check_text_response_match("47");
	if (got_text_match())
		what_num = 47;
	check_text_response_match("48");
	if (got_text_match())
		what_num = 48;
	check_text_response_match("49");
	if (got_text_match())
		what_num = 49;
	check_text_response_match("50");
	if (got_text_match())
		what_num = 50;
	check_text_response_match("51");
	if (got_text_match())
		what_num = 51;
	check_text_response_match("52");
	if (got_text_match())
		what_num = 52;
	check_text_response_match("53");
	if (got_text_match())
		what_num = 53;
	check_text_response_match("54");
	if (got_text_match())
		what_num = 54;
	check_text_response_match("55");
	if (got_text_match())
		what_num = 55;
	check_text_response_match("56");
	if (got_text_match())
		what_num = 56;
	check_text_response_match("57");
	if (got_text_match())
		what_num = 57;
	check_text_response_match("58");
	if (got_text_match())
		what_num = 58;
	check_text_response_match("59");
	if (got_text_match())
		what_num = 59;
	check_text_response_match("60");
	if (got_text_match())
		what_num = 60;
	check_text_response_match("61");
	if (got_text_match())
		what_num = 61;
	check_text_response_match("62");
	if (got_text_match())
		what_num = 62;
	check_text_response_match("63");
	if (got_text_match())
		what_num = 63;
	check_text_response_match("64");
	if (got_text_match())
		what_num = 64;
	check_text_response_match("65");
	if (got_text_match())
		what_num = 65;
	check_text_response_match("66");
	if (got_text_match())
		what_num = 66;
	check_text_response_match("67");
	if (got_text_match())
		what_num = 67;
	check_text_response_match("68");
	if (got_text_match())
		what_num = 68;
	check_text_response_match("69");
	if (got_text_match())
		what_num = 69;
	check_text_response_match("70");
	if (got_text_match())
		what_num = 70;
	check_text_response_match("71");
	if (got_text_match())
		what_num = 71;
	check_text_response_match("72");
	if (got_text_match())
		what_num = 72;
	check_text_response_match("73");
	if (got_text_match())
		what_num = 73;
	check_text_response_match("74");
	if (got_text_match())
		what_num = 74;
	check_text_response_match("75");
	if (got_text_match())
		what_num = 75;
	check_text_response_match("76");
	if (got_text_match())
		what_num = 76;
	check_text_response_match("77");
	if (got_text_match())
		what_num = 77;
	check_text_response_match("78");
	if (got_text_match())
		what_num = 78;
	check_text_response_match("79");
	if (got_text_match())
		what_num = 79;
	check_text_response_match("80");
	if (got_text_match())
		what_num = 80;
	check_text_response_match("81");
	if (got_text_match())
		what_num = 81;
	check_text_response_match("82");
	if (got_text_match())
		what_num = 82;
	check_text_response_match("83");
	if (got_text_match())
		what_num = 83;
	check_text_response_match("84");
	if (got_text_match())
		what_num = 84;
	check_text_response_match("85");
	if (got_text_match())
		what_num = 85;
	check_text_response_match("86");
	if (got_text_match())
		what_num = 86;
	check_text_response_match("87");
	if (got_text_match())
		what_num = 87;
	check_text_response_match("88");
	if (got_text_match())
		what_num = 88;
	check_text_response_match("89");
	if (got_text_match())
		what_num = 89;
	check_text_response_match("90");
	if (got_text_match())
		what_num = 90;
	check_text_response_match("91");
	if (got_text_match())
		what_num = 91;
	check_text_response_match("92");
	if (got_text_match())
		what_num = 92;
	check_text_response_match("93");
	if (got_text_match())
		what_num = 93;
	check_text_response_match("94");
	if (got_text_match())
		what_num = 94;
	check_text_response_match("95");
	if (got_text_match())
		what_num = 95;
	check_text_response_match("96");
	if (got_text_match())
		what_num = 96;
	check_text_response_match("97");
	if (got_text_match())
		what_num = 97;
	check_text_response_match("98");
	if (got_text_match())
		what_num = 98;
	check_text_response_match("99");
	if (got_text_match())
		what_num = 99;
	check_text_response_match("100");
	if (got_text_match())
		what_num = 100;
		
	// Make sure the player actually entered something correct, and if not,
	// start over.
	if (what_num == 0) {
		message_dialog("Unfortunately, that was not an integer between 1 and 100. (Again, sample responses would include _15,_ _37,_ or _41._)","Let's try again.");
		set_state_continue(11);
	}
	set_state_continue(which_state);
break;

beginstate 12; //set intelligence
	if(progress == 0){
		progress = 1;
		clear_buffer();
		append_string("How much intelligence?");
		get_buffer_text(prompt);
		which_state = 12;
		set_state_continue(11);
	}
	else{
		alter_stat(0,2,what_num - get_stat(0,2));
		print_big_str("Intelligence=",get_stat(0,2),"");
		progress = 0;
	}
break;

beginstate 13; //set mage skill
	if(progress == 0){
		progress = 1;
		clear_buffer();
		append_string("How much mage skill?");
		get_buffer_text(prompt);
		which_state = 13;
		set_state_continue(11);
	}
	else{
		alter_stat(0,11,what_num - get_stat(0,11));
		print_big_str("Mage Skill=",get_stat(0,11),"");
		progress = 0;
	}
break;

beginstate 14; //set priest skill
	if(progress == 0){
		progress = 1;
		clear_buffer();
		append_string("How much priest skill?");
		get_buffer_text(prompt);
		which_state = 14;
		set_state_continue(11);
	}
	else{
		alter_stat(0,12,what_num - get_stat(0,12));
		print_big_str("Priest Skill=",get_stat(0,12),"");
		progress = 0;
	}
break;

beginstate 15; //set mage spells levels
	if(progress == 0){
		progress = 1;
		clear_buffer();
		append_string("What level of mage spells?");
		get_buffer_text(prompt);
		which_state = 15;
		set_state_continue(11);
	}
	else{
		x = 0;
		while(x < 20){
			change_spell_level(0,0,x,what_num - get_spell_level(0,0,x));
			x = x + 1;
		}
		progress = 0;
	}
break;

beginstate 16; //set priest spells levels
	if(progress == 0){
		progress = 1;
		clear_buffer();
		append_string("What level of priest spells?");
		get_buffer_text(prompt);
		which_state = 16;
		set_state_continue(11);
	}
	else{
		x = 0;
		while(x < 20){
			change_spell_level(0,1,x,what_num - get_spell_level(0,1,x));
			x = x + 1;
		}
		progress = 0;
	}
break;

beginstate 17; //set magery
	if(progress == 0){
		progress = 1;
		clear_buffer();
		append_string("How much magery?");
		get_buffer_text(prompt);
		which_state = 17;
		set_state_continue(11);
	}
	else{
		alter_stat(0,25,what_num - get_stat(0,25));
		print_big_str("Magery=",get_stat(0,25),"");
		progress = 0;
	}
break;

beginstate 18; //set damager platform
	if(progress == 0){
		progress = 1;
		clear_buffer();
		append_string("How much damage?");
		get_buffer_text(prompt);
		which_state = 18;
		set_state_continue(11);
	}
	else{
		set_flag(1,1,what_num);		
		print_big_str("Damage=",get_flag(1,1),"");
		progress = 0;
	}
break;

beginstate 19; //do damage on platform
	x = get_health(0);
	damage_char(char_on_loc(36,27),get_flag(1,1), get_flag(1,2));
	y = get_health(0);
	clear_buffer();
	append_string("takes ");
	append_number(x - y);
	if(get_flag(1,2)==0)
		append_string(" weapon damage.");
	else if(get_flag(1,2)==1)
		append_string(" fire damage.");
	else if(get_flag(1,2)==2)
		append_string(" poison damage.");
	else if(get_flag(1,2)==3)
		append_string(" magic damage.");
	else if(get_flag(1,2)==4)
		append_string(" unblockable damage.");
	else if(get_flag(1,2)==5)
		append_string(" cold damage.");
	else if(get_flag(1,2)==6)
		append_string(" acid damage.");
	get_buffer_text(prompt);
	print_named_str(0,prompt);
break;

beginstate 20;
	what_num = -1;
	while(what_num == -1){
		get_text_response("What damage type?");
		check_text_response_match("weapon");
		if (got_text_match())
			what_num = 0;
		check_text_response_match("fire");
		if (got_text_match())
			what_num = 1;
		check_text_response_match("poison");
		if (got_text_match())
			what_num = 2;
		check_text_response_match("magic");
		if (got_text_match())
			what_num = 3;
		check_text_response_match("unblockable");
		if (got_text_match())
			what_num = 4;
		check_text_response_match("cold");
		if (got_text_match())
			what_num = 5;
		check_text_response_match("acid");
		if (got_text_match())
			what_num = 6;
		check_text_response_match("melee");
		if (got_text_match())
			what_num = 0;
		check_text_response_match("unblock");
		if (got_text_match())
			what_num = 4;
		check_text_response_match("ice");
		if (got_text_match())
			what_num = 5;
		check_text_response_match("w");
		if (got_text_match())
			what_num = 0;
		check_text_response_match("f");
		if (got_text_match())
			what_num = 1;
		check_text_response_match("p");
		if (got_text_match())
			what_num = 2;
		check_text_response_match("m");
		if (got_text_match())
			what_num = 3;
		check_text_response_match("u");
		if (got_text_match())
			what_num = 4;
		check_text_response_match("c");
		if (got_text_match())
			what_num = 5;
		check_text_response_match("a");
		if (got_text_match())
			what_num = 6;
		check_text_response_match("0");
		if (got_text_match())
			what_num = 0;
		check_text_response_match("1");
		if (got_text_match())
			what_num = 1;
		check_text_response_match("2");
		if (got_text_match())
			what_num = 2;
		check_text_response_match("3");
		if (got_text_match())
			what_num = 3;
		check_text_response_match("4");
		if (got_text_match())
			what_num = 4;
		check_text_response_match("5");
		if (got_text_match())
			what_num = 5;
		check_text_response_match("6");
		if (got_text_match())
			what_num = 6;
	}
	if(what_num==0)
		print_str("Set to weapon damage.");
	else if(what_num==1)
		print_str("Set to fire damage");
	else if(what_num==2)
		print_str("Set to poison damage");
	else if(what_num==3)
		print_str("Set to magic damage");
	else if(what_num==4)
		print_str("Set to unblockable damage");
	else if(what_num==5)
		print_str("Set to cold damage");
	else if(what_num==6)
		print_str("Set to acid damage");
	set_flag(1,2,what_num);
break;

beginstate 21; //set endurance
	if(progress == 0){
		progress = 1;
		clear_buffer();
		append_string("How much endurance?");
		get_buffer_text(prompt);
		which_state = 21;
		set_state_continue(11);
	}
	else{
		alter_stat(0,3,what_num - get_stat(0,3));
		change_char_health(0,get_max_health(0));
		print_big_str("Endurance=",get_stat(0,3),"");
		progress = 0;
	}
break;